package com.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StudentManagementSystem {
    public static void main(String[] args) {
        // 创建主窗口
        JFrame frame = new JFrame("学生管理系统");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 800);
        frame.setLayout(new GridLayout(0, 2));

        // 添加组件
        // 学号
        JLabel idLabel = new JLabel("学号:");
        JTextField idField = new JTextField();
        frame.add(idLabel);
        frame.add(idField);

        // 姓名
        JLabel nameLabel = new JLabel("姓名:");
        JTextField nameField = new JTextField();
        frame.add(nameLabel);
        frame.add(nameField);

        // 学院
        JLabel collegeLabel = new JLabel("学院:");
        String[] colleges = {"计算机学院", "信息工程学院", "电子工程学院","软件学院"};
        JComboBox<String> collegeCombo = new JComboBox<>(colleges);
        frame.add(collegeLabel);
        frame.add(collegeCombo);

        // 专业
        JLabel majorLabel = new JLabel("专业:");
        String[] majors = {"网络安全", "软件工程", "通信工程"};
        JComboBox<String> majorCombo = new JComboBox<>(majors);
        frame.add(majorLabel);
        frame.add(majorCombo);

        // 班级
        JLabel classLabel = new JLabel("班级:");
        String[] classes = {"XX2301", "XX2302", "XX2303","XX2304"};
        JComboBox<String> classCombo = new JComboBox<>(classes);
        frame.add(classLabel);
        frame.add(classCombo);

        // 性别
        JLabel genderLabel = new JLabel("性别:");
        JRadioButton maleButton = new JRadioButton("男");
        JRadioButton femaleButton = new JRadioButton("女");
        ButtonGroup genderGroup = new ButtonGroup();
        genderGroup.add(maleButton);
        genderGroup.add(femaleButton);
        JPanel genderPanel = new JPanel();
        genderPanel.add(maleButton);
        genderPanel.add(femaleButton);
        frame.add(genderLabel);
        frame.add(genderPanel);

        // 籍贯
        JLabel provinceLabel = new JLabel("籍贯:");
        String[] provinces = {"请选择省份", "北京", "上海", "广东","辽宁","黑龙江","吉林"};
        JComboBox<String> provinceCombo = new JComboBox<>(provinces);
        frame.add(provinceLabel);
        frame.add(provinceCombo);

        // 爱好
        JLabel hobbyLabel = new JLabel("爱好:");
        JCheckBox footballCheck = new JCheckBox("足球");
        JCheckBox basketballCheck = new JCheckBox("篮球");
        JCheckBox tennisCheck = new JCheckBox("网球");
        JCheckBox yumaoCheck = new JCheckBox("羽毛球");
        JCheckBox singCheck = new JCheckBox("唱歌");

        JPanel hobbyPanel = new JPanel();
        hobbyPanel.add(footballCheck);
        hobbyPanel.add(basketballCheck);
        hobbyPanel.add(tennisCheck);
        hobbyPanel.add(yumaoCheck);
        hobbyPanel.add(singCheck);
        frame.add(hobbyLabel);
        frame.add(hobbyPanel);

        // 备注
        JLabel remarkLabel = new JLabel("备注:");
        JTextArea remarkArea = new JTextArea(3, 20);
        frame.add(remarkLabel);
        frame.add(new JScrollPane(remarkArea));

        // 提交和重置按钮
        JButton submitButton = new JButton("提交");
        JButton resetButton = new JButton("重置");

        // 提交按钮事件
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String info = "学号：" + idField.getText() +
                        "\n姓名：" + nameField.getText() +
                        "\n学院：" + collegeCombo.getSelectedItem() +
                        "\n专业：" + majorCombo.getSelectedItem() +
                        "\n班级：" + classCombo.getSelectedItem() +
                        "\n性别：" + (maleButton.isSelected() ? "男" : "女") +
                        "\n籍贯：" + provinceCombo.getSelectedItem() +
                        "\n爱好：" + (footballCheck.isSelected() ? "足球 " : "") +
                        (basketballCheck.isSelected() ? "篮球 " : "") +
                        (tennisCheck.isSelected() ? "网球" : "") +
                        (yumaoCheck.isSelected() ? "羽毛球" : "")+
                        (singCheck.isSelected() ? "唱歌" : "")+
                "\n备注：" + remarkArea.getText();

                JOptionPane.showMessageDialog(frame, info, "学生信息", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        // 重置按钮事件
        resetButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                idField.setText("");
                nameField.setText("");
                collegeCombo.setSelectedIndex(0);
                majorCombo.setSelectedIndex(0);
                classCombo.setSelectedIndex(0);
                genderGroup.clearSelection();
                provinceCombo.setSelectedIndex(0);
                footballCheck.setSelected(false);
                basketballCheck.setSelected(false);
                tennisCheck.setSelected(false);
                remarkArea.setText("");
            }
        });

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(submitButton);
        buttonPanel.add(resetButton);

        frame.add(buttonPanel);

        // 显示窗口
        frame.setVisible(true);
    }
}

